home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Graphics / Plotting / aa_Intel_Only / Gnuplot / GnuplotSource / term / amiga.trm < prev    next >
Encoding:
Text File  |  1995-06-12  |  9.6 KB  |  334 lines

  1. /*
  2.  * $Id: amiga.trm,v 1.5 1993/05/18 03:56:37 davis Exp $
  3.  *
  4.  */
  5.  
  6. /* GNUPLOT - amiga.trm */
  7. /*
  8.  * Copyright (C) 1991, 1992
  9.  *
  10.  * Permission to use, copy, and distribute this software and its
  11.  * documentation for any purpose with or without fee is hereby granted, 
  12.  * provided that the above copyright notice appear in all copies and 
  13.  * that both that copyright notice and this permission notice appear 
  14.  * in supporting documentation.
  15.  *
  16.  * Permission to modify the software is granted, but not the right to
  17.  * distribute the modified code.  Modifications are to be distributed 
  18.  * as patches to released version.
  19.  *  
  20.  * This software  is provided "as is" without express or implied warranty.
  21.  * 
  22.  * This file is included by ../term.c.
  23.  *
  24.  * This terminal driver supports:
  25.  *   Amiga Custom Screen
  26.  *
  27.  * AUTHORS
  28.  *   Carsten Steger
  29.  * 
  30.  *   Pat R. Empleo      Slightly modified for Aztec C v5.2a (beta); sort of
  31.  *   08/27/91           supports overscan; for large WB 2.0 virtual screens,
  32.  *                      we limit the plot size so we don't have to scroll
  33.  *                      around (not fun).
  34.  *
  35.  *   Carsten Steger     Modified to support Kickstart 2.0.
  36.  *   09/11/91           Opens a text overscan screen when used with WB 2.0.
  37.  *                      Discerns between NTSC and PAL Amigas when used with
  38.  *                      WB 1.3 and lower.
  39.  *
  40.  *   Pat R. Empleo      Defined some 2.0 stuff in order to get Aztec C to
  41.  *   09/20/91           work with Carsten's new code (see above).  When
  42.  *                      KS/WB 2.0 support gets implemented in Aztec C, this
  43.  *                      kludge will get deleted! 
  44.  *                      (Aztec C release 5.2 beta)
  45.  *
  46.  * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
  47.  * 
  48.  */
  49.  
  50. #ifdef AMIGA_AC_5
  51. #include <intuition/intuitionbase.h>
  52. #include <intuition/screens.h>
  53. #include <graphics/text.h>
  54. #include <graphics/gfxbase.h>
  55. #else
  56. /* You will have to use the Kickstart 2.0 header files for this to compile */
  57. #include <exec/types.h>
  58. #include <intuition/intuitionbase.h>
  59. #include <graphics/gfxbase.h>
  60. #include <proto/intuition.h>
  61. #include <proto/graphics.h>
  62. #include <proto/exec.h>
  63. #include <proto/diskfont.h>
  64. #endif
  65.  
  66. extern char *getenv();
  67. #ifndef AMIGA_AC_5
  68. extern char *strchr();
  69. #endif
  70.  
  71. #define AMIGA_XMAX 640
  72. #define AMIGA_YMAX 512
  73.  
  74. #define AMIGA_VCHAR (12)
  75. #define AMIGA_HCHAR (8)
  76. #define AMIGA_VTIC (AMIGA_YMAX/80)
  77. #define AMIGA_HTIC (AMIGA_XMAX/80)
  78. /* The origin is in the upper left hand corner, so we have to translate */
  79. /* and flip the coordinates: */
  80. #define AMIGA_VTF(y) (AMIGA_ymax-1-(y))
  81.  
  82.  
  83. struct IntuitionBase *IntuitionBase;
  84. struct GfxBase *GfxBase;
  85. struct Library *DiskfontBase;
  86. static struct TextAttr AMIGA_Font = {
  87.   "topaz.font",TOPAZ_EIGHTY,FS_NORMAL,FPF_ROMFONT
  88. };
  89. static struct TextFont *AMIGA_TextFont;
  90. static struct NewScreen AMIGA_NewScreen = {
  91.   0,0,AMIGA_XMAX,AMIGA_YMAX,4,15,0,HIRES|LACE,
  92.   CUSTOMSCREEN|SCREENBEHIND|SCREENQUIET,NULL,NULL,NULL,NULL
  93. };
  94. static struct Screen *AMIGA_Screen;
  95. static UWORD AMIGA_Colors [] = {
  96.   0x000,0xfff,0xbbb,0x0f0,0xf00,0x00f,0x3ca,0xf0f,
  97.   0x94d,0x0ff,0x82f,0xff0,0x0af,0xc5e,0xfa2,0xf44
  98. };
  99. static int AMIGA_slinetype;
  100. static enum JUSTIFY AMIGA_justify = LEFT;
  101. static unsigned int AMIGA_ymax,AMIGA_xmax; 
  102. static WORD AMIGA_cwd,AMIGA_cht,AMIGA_bsl,AMIGA_vadj;
  103. static struct TagItem AMIGA_ScrTagList[] = {
  104.   {SA_Overscan,OSCAN_TEXT},{TAG_DONE,0}
  105. };
  106.  
  107.  
  108. AMIGA_reset()
  109. {
  110.   if (AMIGA_TextFont != NULL) CloseFont(AMIGA_TextFont);
  111.   if (DiskfontBase != NULL) CloseLibrary(DiskfontBase);
  112.   if (AMIGA_Screen != NULL) CloseScreen(AMIGA_Screen);
  113.   if (IntuitionBase != NULL) CloseLibrary(IntuitionBase);
  114.   if (GfxBase != NULL) CloseLibrary(GfxBase);
  115.   AMIGA_TextFont = NULL;
  116.   DiskfontBase = NULL;
  117.   AMIGA_Screen = NULL;
  118.   IntuitionBase = NULL;
  119.   GfxBase = NULL;
  120. }
  121.  
  122.  
  123. AMIGA_init()
  124. {
  125.   static char fontname[80],*gnufont,*search;
  126.   static int fsize;
  127.   static char *test_str =
  128.     " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
  129.   static WORD test_len,test_pxl;
  130.  
  131.  
  132. #ifdef AMIGA_SC_6_1
  133.   /* Install exit trap in case of abnormal termination (see below). */
  134.   int AMIGA_exit();
  135.   if (!onexit(&AMIGA_exit)) {
  136.     fprintf(stderr,"Couldn't set exit trap\n");
  137.     exit(20);
  138.   }
  139. #endif
  140.   GfxBase = (struct GfxBase *) OpenLibrary("graphics.library",0);
  141.   if (GfxBase == NULL) {
  142.     fprintf(stderr,"No Graphics-Library\n");
  143.     AMIGA_reset();
  144.     exit(20);
  145.   }
  146.   IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library",0);
  147.   if (IntuitionBase == NULL) {
  148.     fprintf(stderr,"No Intuition-Library\n");
  149.     AMIGA_reset();
  150.     exit(20);
  151.   }
  152.   if (IntuitionBase->LibNode.lib_Version <= 34) {
  153.     /* We compute the vertical resolution for those poor NTSC-souls   :-)   */
  154.     if (GfxBase->DisplayFlags & PAL) AMIGA_ymax = 512;
  155.     else AMIGA_ymax = 400;
  156.     AMIGA_xmax = 640;
  157.     AMIGA_NewScreen.Width = AMIGA_xmax;
  158.     AMIGA_NewScreen.Height = AMIGA_ymax;
  159.     AMIGA_Screen = OpenScreen(&AMIGA_NewScreen);
  160.     if (AMIGA_Screen == NULL) {
  161.       fprintf(stderr,"No Screen\n");
  162.       AMIGA_reset();
  163.       exit(20);
  164.     }
  165.   } else {
  166.     /* Kickstart 2.0 support */
  167.     AMIGA_NewScreen.Width = STDSCREENWIDTH;
  168.     AMIGA_NewScreen.Height = STDSCREENHEIGHT;
  169.     AMIGA_Screen = OpenScreenTagList(&AMIGA_NewScreen,AMIGA_ScrTagList);
  170.     if (AMIGA_Screen == NULL) {
  171.       fprintf(stderr,"No Screen\n");
  172.       AMIGA_reset();
  173.       exit(20);
  174.     }
  175.     AMIGA_xmax = AMIGA_Screen->Width;
  176.     AMIGA_ymax = AMIGA_Screen->Height;
  177.   }
  178.   term_tbl[term].xmax = AMIGA_xmax;
  179.   term_tbl[term].ymax = AMIGA_ymax;
  180.   gnufont = getenv("GNUFONT");
  181.   if (gnufont != NULL ) {
  182.     search = strchr(gnufont,'/');
  183.     if (search != NULL) {
  184.       *search++ = '\0';
  185.       strncpy(fontname,gnufont,74);
  186.       strcat(fontname,".font");
  187.       sscanf(search,"%d",&fsize);
  188.       /* Avoid opening "diskfont.library" if a built-in font is desired */
  189.       if ((strcmp("topaz.font",fontname) == 0) &&
  190.         ((fsize == TOPAZ_EIGHTY) || (fsize == TOPAZ_SIXTY))) {
  191.         AMIGA_Font.ta_Name = fontname;
  192.         AMIGA_Font.ta_YSize = fsize;
  193.         AMIGA_Font.ta_Style = FS_NORMAL;
  194.         AMIGA_Font.ta_Flags = FPF_ROMFONT;
  195.         AMIGA_TextFont = OpenFont(&AMIGA_Font);
  196.         if (AMIGA_TextFont != NULL) 
  197.           SetFont(&AMIGA_Screen->RastPort,AMIGA_TextFont);
  198.       } else {
  199.         DiskfontBase = OpenLibrary("diskfont.library",0);
  200.         if (DiskfontBase != NULL) {
  201.           AMIGA_Font.ta_Name = fontname;
  202.           AMIGA_Font.ta_YSize = fsize;
  203.           AMIGA_Font.ta_Style = FS_NORMAL;
  204.           AMIGA_Font.ta_Flags = FPF_ROMFONT|FPF_DISKFONT;
  205.           AMIGA_TextFont = OpenDiskFont(&AMIGA_Font);
  206.           if (AMIGA_TextFont != NULL)
  207.             SetFont(&AMIGA_Screen->RastPort,AMIGA_TextFont);
  208.         }
  209.       }
  210.     }
  211.   }
  212.   /* Width of characters: This works better for proportional fonts than */
  213.   /* AMIGA_Screen->RastPort.TxWidth + AMIGA_Screen->RastPort.TxSpacing */
  214.   test_len = strlen(test_str);
  215.   test_pxl = TextLength(&AMIGA_Screen->RastPort,test_str,test_len);
  216.   AMIGA_cwd = test_pxl / test_len;
  217.   AMIGA_cht = AMIGA_Screen->RastPort.TxHeight; /* Height of characters */
  218.   AMIGA_bsl = AMIGA_Screen->RastPort.TxBaseline; /* Reference line */
  219.   /* Amount by which characters have to be shifted upwards to be */
  220.   /* vertically justified: */
  221.   AMIGA_vadj = AMIGA_bsl / 2;
  222.   term_tbl[term].v_char = AMIGA_cht + 4; /* So lines won't be too close */
  223.   term_tbl[term].h_char = AMIGA_cwd;
  224.   LoadRGB4(&AMIGA_Screen->ViewPort,AMIGA_Colors,16);
  225.   RemakeDisplay();
  226.   AMIGA_slinetype = 1;
  227.   SetAPen(&AMIGA_Screen->RastPort,AMIGA_slinetype);
  228.   SetDrMd(&AMIGA_Screen->RastPort,JAM1);
  229. }
  230.  
  231.  
  232. AMIGA_text()
  233. {
  234.   char c;
  235.   FILE *console;
  236.  
  237.   console = fopen("*","r");
  238.   if (console != NULL) {
  239.     /* Wait for return from the console window */
  240.     c = getc(console); /* This is extremely ugly... Yuk !!!!   >:-(   */
  241.     ungetc(c,stdin); /* Maybe someone else will find a better solution */
  242.     fclose(console);
  243.   }
  244.   ScreenToBack(AMIGA_Screen);
  245. }
  246.  
  247.  
  248. AMIGA_graphics()
  249. {
  250.   SetRast(&AMIGA_Screen->RastPort,0);
  251.   SetAPen(&AMIGA_Screen->RastPort,AMIGA_slinetype);
  252.   ScreenToFront(AMIGA_Screen);
  253. }
  254.  
  255.  
  256. AMIGA_move(x,y)
  257. unsigned int x,y;
  258. {
  259.   if ((x>=AMIGA_xmax) || (y>=AMIGA_ymax)) return;
  260.   Move(&AMIGA_Screen->RastPort,x,AMIGA_VTF(y));
  261. }
  262.  
  263.  
  264. AMIGA_vector(x,y)
  265. unsigned int x,y;
  266. {
  267.   if ((x>=AMIGA_xmax) || (y>=AMIGA_ymax)) return;
  268.   Draw(&AMIGA_Screen->RastPort,x,AMIGA_VTF(y));
  269. }
  270.  
  271.  
  272. AMIGA_linetype(linetype)
  273. int linetype;
  274. {
  275.   if (linetype >= 13) linetype %= 13;
  276.   if (linetype < -2) linetype = -2;
  277.   AMIGA_slinetype = linetype+3;
  278.   SetAPen(&AMIGA_Screen->RastPort,AMIGA_slinetype);
  279. }
  280.  
  281.  
  282. AMIGA_put_text(x,y,str)
  283. unsigned int x,y;
  284. char *str;
  285. {
  286.   LONG len,tx_len;
  287.   WORD xmin,xmax,ymin,ymax;
  288.  
  289.   len = strlen(str);
  290.   tx_len = TextLength(&AMIGA_Screen->RastPort,str,len);
  291.   switch (AMIGA_justify) {
  292.     case LEFT:
  293.       xmin = x;
  294.       xmax = x + tx_len;
  295.       break;
  296.     case CENTRE:
  297.       xmin = x - tx_len / 2;
  298.       xmax = x + tx_len - tx_len / 2; /* aviod roundoff errors ! */
  299.       break;
  300.     case RIGHT:
  301.       xmin = x - tx_len;
  302.       xmax = x;
  303.       break;
  304.   }
  305.   ymin = AMIGA_VTF(y) - AMIGA_vadj;
  306.   ymax = ymin + AMIGA_cht;
  307.   /* Check if character-string lies completely within the screen: */
  308.   if ((xmax >= AMIGA_xmax) || (ymin < 0) || (ymax >= AMIGA_ymax)) return;
  309.   Move(&AMIGA_Screen->RastPort,xmin,ymin+AMIGA_bsl);
  310.   Text(&AMIGA_Screen->RastPort,str,len);
  311. }
  312.  
  313.  
  314. int AMIGA_justify_text(mode)
  315. enum JUSTIFY mode;
  316. {
  317.   AMIGA_justify = mode;
  318.   return TRUE;
  319. }
  320.  
  321.  
  322. /* This function is mainly included if the program terminates abnormally */
  323. /* and the screen and libraries are still open. It closes down all opened */
  324. /* libraries and screens. This happens e.g. when loading "bivariat.demo" */
  325. /* and the stack is smaller than 120000 bytes. */
  326. #ifdef AMIGA_SC_6_1
  327. int AMIGA_exit(rc)
  328. int rc;
  329. {
  330.   AMIGA_reset();
  331.   return rc;
  332. }
  333. #endif
  334.